# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=u-boot-spacemit
pkgver=2022.10.2.0_rc6
_realver=v2.0rc6
pkgrel=1
pkgdesc="u-boot bootloader for spacemit"
url="https://gitee.com/bianbu-linux/uboot-2022.10"
arch="riscv64"
license="GPL-2.0-or-later OFL-1.1 BSD-2-Clause BSD-3-Clause eCos-2.0 IBM-pibs
	ISC LGPL-2.0-only LGPL-2.1-only X11"
options="!check" # no tests
builddir=$srcdir/uboot-2022.10-$_realver

makedepends="$depends_dev
	bash
	bc
	bison
	dtc
	flex
	gnutls-dev
	linux-headers
	opensbi-spacemit
	openssl-dev
	py3-elftools
	py3-setuptools
	python3-dev
	swig
	util-linux-dev
	"
source="$pkgname-$_realver.tar.gz::https://gitee.com/bianbu-linux/uboot-2022.10/repository/archive/$_realver.tar.gz
	020-mbr-support.patch
	021-change-autoboot_stop_str-to-space-key.patch
	022-syslinux-and-script-support.patch
	023-efi_loader-suppress-error-print-message.patch
	"

prepare() {
	default_prepare
	make k1_defconfig
	scripts/config --file .config --disable "PRINT_TIMESTAMP"
}

build() {
	export OPENSBI="/usr/share/opensbi-spacemit/fw_dynamic.itb"
	make
}

package() {
	mkdir -p "$pkgdir"/usr/share/$pkgname
	install -m644 "$builddir"/u-boot.itb "$pkgdir"/usr/share/$pkgname/
	install -m644 "$builddir"/FSBL.bin "$pkgdir"/usr/share/$pkgname/
	install -m644 "$builddir"/bootinfo_emmc.bin "$pkgdir"/usr/share/$pkgname/
}

sha512sums="
efaf47345725dbdb69a84b80cdfb23e896ec6da33a61f418caadc3238b03725b353858c36caae61a5660a9080abe715562644b1bfc47d8e6fcd716831329e4fb  u-boot-spacemit-v2.0rc6.tar.gz
4273ee56ab4ddd6c83c5c32478172785d8a80c4daad6ce3cd77610d5a69d2b19fd880161f11a13daa2ebd8838644cacd75092dc7a878c312881e49af5c0f6269  020-mbr-support.patch
655756f6aa75396c5063ea009a2dd304d6105f5fc9081fc12c30850e061b2ee18335f860f4667fa74a063b66426a76a6399e384bb2439a6198e2a356f2514c27  021-change-autoboot_stop_str-to-space-key.patch
3d621202466861716496aeef6b65dd82febab47cd3b12fecea3bc13a1ba116cf1b15e2b89f85c737455c755310002e295c0205449890ccb73beaa4e261775f25  022-syslinux-and-script-support.patch
d5b1b16e68e0ca8c070440b742ee16293174e26bd2d4202244ef089414c2ab15c92656919110561476cace53b362217b0f91c426641df422cc3813d71c198361  023-efi_loader-suppress-error-print-message.patch
"
